package com.zhsj.OkeHomeConsumption.ui.activity;

import android.os.Bundle;
import android.util.Log;
import android.widget.Button;

import com.zhsj.OkeHomeConsumption.R;
import com.zhsj.OkeHomeConsumption.common.MyActivity;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import cat.ereza.customactivityoncrash.CustomActivityOnCrash;
import cat.ereza.customactivityoncrash.config.CaocConfig;

/**
 * author : Xingdx
 * <p>
 * time   : 2018/10/18
 * desc   : 崩溃处理
 */
public final class MyDefaultErrorActivity extends MyActivity {

    @BindView(R.id.restart_button)
    Button restartButton;
    private CaocConfig config;
    @Override
    protected int getLayoutId() {
        return R.layout.activity_defaulterror;
    }

    @Override
    protected int getTitleId() {
        return R.id.tb_copy_title;
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initData() {
        //可以获取到的四个信息:
        //将堆栈跟踪作为字符串获取。
        String stackString = CustomActivityOnCrash.getStackTraceFromIntent(getIntent());
        Log.d("huangxiaoguo","将堆栈跟踪作为字符串获取==>"+stackString);
        //获取错误报告的Log信息
        String logString = CustomActivityOnCrash.getActivityLogFromIntent(getIntent());
        Log.d("huangxiaoguo","获取错误报告的Log信息==>"+logString);
        // 获取所有的信息
        String allString = CustomActivityOnCrash.getAllErrorDetailsFromIntent(this, getIntent());
        Log.d("huangxiaoguo","获取所有的信息==>"+allString);
        //获得配置信息,比如设置的程序崩溃显示的页面和重新启动显示的页面等等信息
        config = CustomActivityOnCrash.getConfigFromIntent(getIntent());

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @OnClick(R.id.restart_button)
    public void onViewClicked() {
        if (config!=null&&config.getRestartActivityClass()!=null){
            CustomActivityOnCrash.restartApplication(this,config);
        }

    }
}